package com.jfinal.generator.controller;

/**
 * GeneratorDemo
 */
public class GeneratorController {

	private String bean;
	private String path;
	// model路径
	private String model;
	// controller描述
	private String remark;
	// model 类名
	private String modelName;
	// service 所使用包名
	private String servicePackageName;
	// controller 所使用包名
	private String controllerPackageName;
	// controller 文件保存路径
	private String controllerOutputDir;

	protected ControllerGenerator controllerGenerator;

	public GeneratorController(String bean, String path, String model, String remark, String controllerPackageName, String servicePackageName) {
		this.bean = bean;
		this.path = path;
		this.model = model;
		this.remark = remark;
		this.servicePackageName = servicePackageName;
		this.controllerPackageName = controllerPackageName;
		// controller 文件保存路径
		this.controllerOutputDir = System.getProperty("user.dir") + "/src/main/java/" + controllerPackageName.replace('.', '/');
		// model 类名
		this.modelName = model.substring(model.lastIndexOf(".") + 1);
	}

	public void generate() {
		this.controllerGenerator = new ControllerGenerator(bean, path, model, remark, modelName, controllerPackageName, controllerOutputDir, servicePackageName);
		// 生成
		long start = System.currentTimeMillis();
		controllerGenerator.generate();
		long usedTime = (System.currentTimeMillis() - start) / 1000;
		System.out.println("Generate complete in " + usedTime + " seconds.");
	}
}
